﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Resources;
using System.Globalization;
using System.Threading;
using EHTWebsite.Code;

public partial class SanPham : System.Web.UI.Page
{
    public Boolean IsVN = true;
    private String languageCode = "vi-VN";
    private Int32 categoryID = -1;
    private Int32 pageIndex = 1;
    private Int32 pageSize = 12;
    private Int32 totalRecord = 0;

    private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            languageCode = Session[HangSo.LANGUAGE_CODE].ToString();

            if (languageCode == "en-us")
            {
                IsVN = false;
            }

        }
        catch (Exception ex)
        {
        }

        try
        {
            pageIndex = Int32.Parse(Request.QueryString["PageIndex"].ToString());
        }
        catch (Exception ex)
        {
        }

        try
        {
            categoryID = Int32.Parse(Request.QueryString["CategoryID"].ToString());
        }
        catch (Exception ex)
        {
        }

        if (!Page.IsPostBack)
        {
            EHTWebsite.Code.SanPham theSanPham = new EHTWebsite.Code.SanPham();
            theSanPham.DanhMucID = categoryID;
            theSanPham.NoiBat = false;
            theSanPham.TenSanPhamOther = "";
            theSanPham.TenSanPhamVN = "";

            EHTWebsite.Code.DanhMucSanPham theDanhMucSanPham = DanhMucSanPhamProvider.GetDanhMucSanPhamByDanhMucID(categoryID);

            if (theDanhMucSanPham == null)
            {
                theDanhMucSanPham = new DanhMucSanPham();
                theDanhMucSanPham.DanhMucID = -1;
                theDanhMucSanPham.TenDanhMucVN = "tat-ca";
            }

            //pageSize = this.PaggingControl1.PageSize;

            this.rpSanPhams.DataSource = SanPhamProvider.GetSanPhamsForFrontEnd(theSanPham, pageIndex, pageSize, out totalRecord);
            this.rpSanPhams.DataBind();
            //this.PaggingControl1.TotalRecord = totalRecord;
            //this.PaggingControl1.PageURL = "/san-pham/" + theDanhMucSanPham.DanhMucID.ToString() + "/" + theDanhMucSanPham.TenDanhMucVN + ".aspx";

            Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
            LoadLanguage(Thread.CurrentThread.CurrentCulture);
        }
    }

    public void LoadLanguage(CultureInfo ci)
    {
        //this.ltrDanhSachSanPham.Text = rm.GetString("ltrDanhSachSanPham_Title", ci);
    }

    public String FormatStringForUrl(String input)
    {
        return HelpMethod.FormatStringForUrl(input);
    }
}